package top.hidoctor.auscultation.adapter;

import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tang.util.TimeUtil;

import java.util.List;

import top.hidoctor.auscultation.R;
import top.hidoctor.auscultation.bean.ShaichaBean;
import top.hidoctor.auscultation.utils.BirthdayToAgeUtil;

public class ShaichaAdapter extends BaseQuickAdapter<ShaichaBean.ResultBean> {
    public ShaichaAdapter(int layoutResId, List<ShaichaBean.ResultBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ShaichaBean.ResultBean item) {
        TextView aiStatus = helper.getView(R.id.tv_ai_status);
        TextView status = helper.getView(R.id.tv_status);
        helper.setText(R.id.tv_title, item.getNo());
        helper.setOnClickListener(R.id.fl_ai, new OnItemChildClickListener());
        helper.setOnClickListener(R.id.ll_content, new OnItemChildClickListener());

        helper.setText(R.id.tv_creat_time, "创建时间：" + TimeUtil.formatTime(item.getCreatedTime(), TimeUtil.Y_M_D_H_M_S_24));
        helper.setText(R.id.tv_status, item.getStatus() == 10 ? "正在筛查" : item.getStatus() == 20 ? "筛查完成" : item.getStatus() == 30 ? "待确定" : "");
        if (item.getStatus() == 10) {
            status.setTextColor(mContext.getResources().getColor(R.color.c_cccccc));
        } else if (item.getStatus() == 20) {
            status.setTextColor(mContext.getResources().getColor(R.color.blue_main));
        } else if (item.getStatus() == 30) {
            status.setTextColor(mContext.getResources().getColor(R.color.main_yellow));
        }

        if (item.getPatient() != null) {
            helper.setText(R.id.tv_name, "姓名：" + (TextUtils.isEmpty(item.getPatient().getName()) ? "" : item.getPatient().getName()));
            helper.setText(R.id.tv_age, "年龄：" + (item.getPatient().getBirthday() != null ? (BirthdayToAgeUtil.BirthdayToAge(TimeUtil.formatTime(item.getPatient().getBirthday(), TimeUtil.Y_M_D))) : ""));
        }
        helper.setText(R.id.tv_position, "体位：" + (!TextUtils.isEmpty(item.getPosition()) ? item.getPosition() : ""));
        helper.setText(R.id.tv_coordinate, "配合程度：" + (!TextUtils.isEmpty(item.getCoordinate()) ? item.getCoordinate() : ""));

        helper.setText(R.id.tv_ai_status, item.getAiStatus() == 10 ? "分析中" : item.getAiStatus() == 20 ? "分析完成" : "AI分析");
        helper.setText(R.id.tv_ai_status2, item.getAiStatus() == 20 ? "完成分析" : item.getAiStatus() == 30 ? "无法解析" : "");

        if (item.getAiStatus() == 10) {
            Drawable drawableLeft = mContext.getResources().getDrawable(R.mipmap.fenxizhong);
            aiStatus.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, null, null);
            aiStatus.setTextColor(mContext.getResources().getColor(R.color.main_yellow));
            helper.setVisible(R.id.tv_ai_status2, false);

        } else if (item.getAiStatus() == 20) {
            Drawable drawableLeft = mContext.getResources().getDrawable(R.mipmap.ic_ai_fenxi);
            aiStatus.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, null, null);
            aiStatus.setTextColor(mContext.getResources().getColor(R.color.blue_main));
            helper.setVisible(R.id.tv_ai_status2, true);
            helper.setTextColor(R.id.tv_ai_status2, mContext.getResources().getColor(R.color.blue_main));
            helper.setBackgroundRes(R.id.tv_ai_status2, R.drawable.bg_blue_8);
        } else if (item.getAiStatus() == 30) {
            helper.setVisible(R.id.tv_ai_status2, true);
            Drawable drawableLeft = mContext.getResources().getDrawable(R.mipmap.ic_ai_fenxi);
            aiStatus.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, null, null);
            aiStatus.setTextColor(mContext.getResources().getColor(R.color.blue_main));
            helper.setTextColor(R.id.tv_ai_status2, mContext.getResources().getColor(R.color.main_yellow));
            helper.setBackgroundRes(R.id.tv_ai_status2, R.drawable.bg_yellow_8);
        }
    }
}
